<?php

namespace app\qsapi\controller;

use app\qsapi\model\Member;
use app\qsapi\service\BaseService;
use app\qsapi\service\BoxAdService;
use think\response\Json;

/**
 * 公共模块
 */
class Common extends BaseController
{

    protected $noNeedLogin=['version','agreement','adole','spreadlist','popoulist','uploadimage','agreementText','agreementtext','agreementinfo','systemnotice','getagreementinfo'];
    /**
     * 开屏广告
     * @return Json
     */
    public function spreadList(): Json
    {
        return json((new BoxAdService())->getSpreadList($this->request->param()));
    }


    /**
     * 弹窗广告
     * @return Json
     */
    public function popouList(): Json
    {
        $type=request()->get('type','index');
        return json((new BoxAdService())->getPopouList($type));
    }


    /**
     * 检查版本
     * @return Json
     */
    public  function version(): Json
    {
        return json((new BaseService())->getNewLastVersion());
    }

    /**
     * 协议管理
     * @return Json
     */
    public function agreement(): Json
    {
        return json((new BaseService())->getAgreement());
    }

    /**
     * 协议管理内容
     * @return void
     */
    public function agreementText()
    {
        return json((new BaseService())->getAgreementText());
    }

    public  function agreementInfo(){
        $type= request()->get('type','user_agreement');
        $info=(new BaseService())->getAgreementTextInfo($type);
        if(!$info){
            return  '';
        }
        $this->assign('info',$info);
        return $this->fetch();
    }


    /**
     * Desc : 获取协议文本
     * User : you name
     * Date : 2024-03-20 18:14
     * @return mixed|string
     */
    public  function getAgreementInfo(){
        $type= request()->get('type','user_agreement');
        $info=(new BaseService())->getAgreementTextInfo($type);
        if(!$info){
            return json(api_message([],'为获取到相关协议!',0));
        }
        return json(api_message($info,'文本获取成功!'));
    }

    /**
     * 青少年模式弹窗
     * @return void
     */
    public  function adole(){
        return json((new BaseService())->getAdole());
    }

    /**
     * 系统公告
     * @return void
     */
    public  function systemNotice(){

        return json((new BaseService())->getSystemNotice());
    }


    /**
     * 上传图片（支持多图片上传）
     * 备注：1、单文件：file
     *      2、多文件：file[],file[]
     * @return array
     * @since 2020/11/20
     * @author ZhangXuanNeng
     */
    public function uploadImage()
    {

        $error = "";
        // 上传文件(非图片)
        $result = upload_image_new('file', '', $error);
        if (!$result) {
            return json(api_message([], $error,0));
        }
        $ext = $result['ext'];
        $ossUrl = upload_file_2_oss($result['file_dir'],$result['name'],'qnbox');
        if(!$ossUrl['status']){
            return json(api_message([], $ossUrl['msg'],0));
        }
        $cover=$ossUrl['data'];
        $type=1;
        if(in_array($ext,['mp4'])){
           // $cover.="?x-oss-process=video/snapshot,t_1000,m_fast";
            $type=2;
        }
       return  json(api_message(['url'=>$ossUrl['data'],'cover'=>$cover,'type'=>$type],"上传成功" ));

    }







}